package com.hnucm.springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hnucm.springboot.pojo.Student;
import com.hnucm.springboot.service.StudentSercive;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class StudentController {
    @Autowired
    StudentSercive studentSercive;
    @RequestMapping("getstudentlist")
    public String getstudentlist(Model model){
        //save,update(,null),remove
//        QueryWrapper<Student> queryWrapper =new QueryWrapper<>();
        //select * from student where name =test1
//        queryWrapper.eq("name","test1").or();
        //列表->分页 每页显示20条
        /*
        * select * from student limit 20 skip 20*2
        * */
        Page<Student> page=new Page<>(1,3);
        Page<Student> Ipage = studentSercive.getBaseMapper().selectPage(page, null);
        model.addAttribute("studentlist",Ipage.getRecords());
        model.addAttribute("total",Ipage.getTotal());
        return "studentlist.html";
    }
    @RequestMapping("deletestudentbyid")
    public String deletestudentbyid(int id){
        studentSercive.removeById(id);
        return "redirect:/getstudentlist";
    }
}
